package com.xunkids.bos.migration.component.transmission.api.impl;



import com.xunkids.bos.migration.common.exception.RushException;
import com.xunkids.bos.migration.component.transmission.api.MessagePool;
import com.xunkids.bos.migration.component.transmission.api.QueuePublisher;
import com.xunkids.bos.migration.component.transmission.api.QueueSubscriber;
import com.xunkids.bos.migration.component.transmission.api.TransportApi;
import com.xunkids.bos.migration.component.transmission.pojo.RequestMessage;
import com.xunkids.bos.migration.component.transmission.pojo.ResponseMessage;
import com.xunkids.bos.migration.component.transmission.pojo.TransportMessage;


import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * 公共传输服务
 *
 * @author xigexb
 * @version 1.0.0
 * @since 2022/8/27 22:48
 */
public class CommonTransportService implements TransportApi {


    /**
     * 消息池
     */

    /**
     * 队列发布
     */
    private final QueuePublisher publisher;

    private final QueueSubscriber subscriber;

    public CommonTransportService(
                                  QueuePublisher publisher, QueueSubscriber subscriber) {
        this.subscriber = subscriber;
        this.publisher = publisher;
    }


    /**
     * 发送消息
     *
     * @param message 消息
     */
    @Override
    public void sendMessage(RequestMessage message) throws RushException {

        publisher.send(message.topic(), message);
    }

    /**
     * 发起请求
     *
     * @param request 请求
     */
    @Override
    public CompletableFuture<ResponseMessage> request(RequestMessage request) throws RushException {

        //发送消息
        publisher.send(request.topic(), request);
        return null;
    }

    
    /**
     * 响应
     *
     * @param response 响应
     */
    @Override
    public void response(ResponseMessage response) {
    }

    @Override
    public QueueSubscriber getSubscriber() {
        return this.subscriber;
    }
}
